package com.sgb.businessmodule.view.widget;

import android.content.Context;

import androidx.recyclerview.widget.GridLayoutManager;

import com.sgb.businessmodule.R;
import com.sgb.businessmodule.entity.PickFilterEntity;
import com.sgb.businessmodule.view.ui.adapter.PopularFilterAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.view.selection.MaxHeightRecyclerView;

import java.util.List;

public class BusinessSelectionTypePopWindow extends BasePopWindow {

    private PopularFilterAdapter filterAdapter;

    public BusinessSelectionTypePopWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_business_selection;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        MaxHeightRecyclerView recyclerView = holder.getPop().findViewById(R.id.type_list);
        filterAdapter = new PopularFilterAdapter(mContext, R.layout.item_popular_filter1, null);
        filterAdapter.setItemSelect(true);
        filterAdapter.setDefItem(-1);
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
        recyclerView.setAdapter(filterAdapter);
        filterAdapter.setOnItemClick(new AdapterOnItemClick<PickFilterEntity>() {
            @Override
            public void onItemClick(PickFilterEntity entity, int position) {
                onResultClick.result(entity, position, null);
                dissMiss();
            }
        });
    }

    public void setData(List<PickFilterEntity> data) {
        filterAdapter.setDatas(data);
    }

    public void setDefItem(int position) {
        filterAdapter.setDefItem(position);
    }
}
